﻿using System;
class BracketCheck
{
    static void Main()
    {
        bool isCorect = true;
        int indexOpen = 0;
        int curindexOpen = 0;
        int indexClose = 0;
        int curindexClose = 0;
        int openCount = 0;
        int closeCount = 0;
        Console.Write("input expression: ");
        string expression = Console.ReadLine();
        while ((indexOpen != -1) && (indexClose != -1))
        {
            indexOpen = expression.IndexOf('(', curindexOpen);
            curindexOpen = indexOpen + 1;
            if (indexOpen != -1)
            {
                openCount++;
            }
            indexClose = expression.IndexOf(')', curindexClose);
            curindexClose = indexClose + 1;
            if (indexClose != -1)
            {
                closeCount++;
            }
            if (indexClose < indexOpen)
            {
                isCorect = false;
                break;
            }
        }
        if (openCount != closeCount)
        {
            isCorect = false;
        }
        if (isCorect == true)
        {
            Console.Write("expression {0} is coreect!", expression);
        }
        else
        {
            Console.Write("expression {0} is not coreect!", expression);
        }
        Console.ReadLine();
    }
}

